<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <script src="../js/prop-types.js"></script>
</head>

<body>
    <div id="test"></div>
  
    <script type="text/babel">
        class Count extends React.Component{

            constructor(){
                console.log('constructor');
                super()
                this.state={count:0}
            }

            // 加法的回调函数
            add=()=>{
                let {count} = this.state
                this.setState({count:count+1})
            }
            // 卸载软件的回调函数
            death=()=>{
                ReactDOM.unmountComponentAtNode(document.getElementById('test'))
            }
            // 强制更新一下
            must=()=>{
                this.forceUpdate()
            }

            // 组件将要挂载
            componentWillMount(){
                console.log('componentWillMount');
            }
            // 组件挂载完毕
            componentDidMount(){
                console.log('componentDidMount');
            }
            // 组件将要卸载
            componentWillUnmount(){
                console.log('componentWillUnmount');
            }
            
            // 控制组件是否更新（该狗子可以进行组件的优化）
            shouldComponentUpdate(){
                console.log('shouldComponentUpdate');
                return false //阀门关闭时
            }
            // 组件将要更新
            componentWillUpdate(){
                console.log('componentWillUpdate');
            }
            // 组件更新完毕
            componentDidUpdate(){
                console.log('componentDidUpdate');
            }
            
            // 


            // 生命周期函数
            render(){
                console.log('render');
                return (
                    <div>
                        <h1>当前求和：{this.state.count}</h1>
                        <button onClick={this.add}>点我+1</button>
                        <button onClick={this.death}>点我卸载组件</button>
                        <button onClick={this.must}>不加不减，就是强制调用render</button>
                    </div>
                )
            }
        }
        ReactDOM.render(<Count/>,document.getElementById('test'))
    
    </script>
</body>

</html>